//
//  UILabel+UseExt.swift
//  jrw
//
//  Created by cabinzhao on 5/22/17.
//  Copyright © 2017 武汉玖信普惠金融信息服务有限公司. All rights reserved.
//

import UIKit

extension UILabel {
    
    public func setStrsColor(strs:[String], color:UIColor) {
        
        if let oldStr = self.text as NSString? {
            let attriStr = NSMutableAttributedString(string: oldStr as String)
            for str in strs {
                attriStr.addAttributes([NSAttributedStringKey.foregroundColor : color], range: oldStr.range(of: str))
            }
            self.attributedText = attriStr
        }
    }
    
    public func setStrsArrStyle(strs:[String], color:UIColor, fontSize:CGFloat) {
        
        if let oldStr = self.text as NSString? {
            let attriStr = NSMutableAttributedString(string: oldStr as String)
            for str in strs {
                attriStr.addAttributes([NSAttributedStringKey.foregroundColor : color, NSAttributedStringKey.font: UIFont.systemFont(ofSize: fontSize)], range: oldStr.range(of: str))
            }
            self.attributedText = attriStr
        }
    }
    
    //设置富文本
    public func setStr(str:String, fontSize:CGFloat) {
        if let oldStr = self.text as NSString? {
            let attriStr = NSMutableAttributedString(string: oldStr as String)
            attriStr.addAttributes([NSAttributedStringKey.font: UIFont.systemFont(ofSize: fontSize)], range: oldStr.range(of: str))
            self.attributedText = attriStr
        }
    }
    
}

